package com.tools.cleanmaster.scenenew;


import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import java.util.List;

/**
 * Created by wuyanfei on 15/12/3.
 * 省电带量相关工具类
 */
public class BatterySaverHelper {

    public static final String DX_BATTERY_PACKAGENAME = "com.dianxinos.dxbs";
    public static final String DXPOWERSAVE_ACTION = "com.dianxinos.powermanager.MAINACTIVITY";
    private static final String DXPOWERSAVE_PACKAGENAME = DX_BATTERY_PACKAGENAME;
    private static final String DXPOWERSAVE_PACKAGENAME_PAID = "com.dianxinos.dxbs.paid";


    private static final String[] sBatterySaverPkgs = {
            DXPOWERSAVE_PACKAGENAME_PAID, DXPOWERSAVE_PACKAGENAME
    };



    public static ResolveInfo getInstalledBatterySaverInfo(Context context) {
        PackageManager pm = context.getPackageManager();
        Intent intent = new Intent();
        intent.setAction(DXPOWERSAVE_ACTION);
        List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
        if (activities != null) {
            for (String pkg : sBatterySaverPkgs) {
                for (ResolveInfo info : activities) {
                    final ActivityInfo ai = info.activityInfo;
                    if (ai.packageName != null && ai.packageName.equals(pkg)) {
                        return info;
                    }
                }
            }
        }
        return null;
    }
}
